package com.team9.fitness.config;

import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 缓存配置类
 * 为应用添加缓存支持，提升性能
 */
@Configuration
@EnableCaching
public class CacheConfig {

    /**
     * 配置缓存管理器
     */
    @Bean
    public CacheManager cacheManager() {
        ConcurrentMapCacheManager cacheManager = new ConcurrentMapCacheManager();
        
        // 定义缓存名称 - 使用Arrays.asList()创建集合
        cacheManager.setCacheNames(java.util.Arrays.asList(
            "communityPosts",      // 社区帖子缓存
            "postComments",        // 帖子评论缓存
            "userProfiles",        // 用户资料缓存
            "exerciseRecords",     // 运动记录缓存
            "dietRecords",         // 饮食记录缓存
            "foodInfo",           // 食物信息缓存
            "exerciseInfo"        // 运动信息缓存
        ));
        
        return cacheManager;
    }
}
